package com.tsingtree.modular.controller.view;

import com.tsingtree.base.auth.annotion.Permission;
import com.tsingtree.modular.entity.NanSellAnnounceAdvert;
import com.tsingtree.modular.model.params.NanSellAnnounceAdvertParam;
import com.tsingtree.modular.service.NanSellAnnounceAdvertService;
import com.tsingtree.roses.core.base.controller.BaseController;
import com.tsingtree.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 社区帖子广告控制器
 *
 * @author jagger
 * @since 2025-10-17
 */
@Controller
@RequestMapping("/nanSellAdvert")
public class NanSellAnnounceAdvertController extends BaseController {

    private String PREFIX = "/nanSellAdvert";

    @Autowired
    private NanSellAnnounceAdvertService nanSellAnnounceAdvertService;

    /**
     * 跳转到广告管理页面
     */
    @RequestMapping("/list")
    public String list(Integer sellAnnounceId) {
        return PREFIX + "/list.html";
    }

    /**
     * 根据社区帖子ID获取广告列表（API接口）
     */
    @ResponseBody
    @RequestMapping("/listData/{sellAnnounceId}")
    public ResponseData listData(@PathVariable Integer sellAnnounceId) {
        List<NanSellAnnounceAdvert> list = nanSellAnnounceAdvertService.findBySellAnnounceId(sellAnnounceId);
        return ResponseData.success(list);
    }

    /**
     * 新增广告
     */
    @RequestMapping("/add")
    @Permission
    @ResponseBody
    public ResponseData add(NanSellAnnounceAdvertParam nanSellAnnounceAdvertParam) {
        this.nanSellAnnounceAdvertService.add(nanSellAnnounceAdvertParam);
        return ResponseData.success();
    }

    /**
     * 删除广告
     */
    @RequestMapping("/delete")
    @Permission
    @ResponseBody
    public ResponseData delete(NanSellAnnounceAdvertParam nanSellAnnounceAdvertParam) {
        this.nanSellAnnounceAdvertService.delete(nanSellAnnounceAdvertParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(NanSellAnnounceAdvertParam nanSellAnnounceAdvertParam) {
        NanSellAnnounceAdvert detail = this.nanSellAnnounceAdvertService.findById(nanSellAnnounceAdvertParam);
        return ResponseData.success(detail);
    }

}
